Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(router): Add new JWT authentication variants and use them #2835

Merged
merged 9 commits into from
Nov 13, 2023

Conversation

ThisIsMani
Copy link
Contributor

@ThisIsMani ThisIsMani commented Nov 10, 2023

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

  • Added merchant create routes
  • Add dashboard routes
  • add user creation routes
  • Support user based JWT auth for routes

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

To make some routes accessible with JWT authentication

How did you test it?

Postman.

Test Cases

  1. New APIs
curl --location 'http://localhost:8080/user/v2/signin' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "email",
    "password": "password"
}'
curl --location 'http://localhost:8080/user/v2/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "email",
    "password": "password"
}'
curl --location 'http://localhost:8080/user/signin' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "email",
    "password": "password"
}'
curl --location 'http://localhost:8080/user/signup' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "email",
    "password": "password"
}'

All the above APIs will give the following response

{
    "token": "JWT Token",
    "merchant_id": "merchant_id",
    "name": "user name",
    "email": "email",
    "verification_days_left": null,
    "user_role": "org_admin"
}
  1. Old APIs
    The following APIs will now work with jwt tokens in the authorization header.
  • Steps:
    a. Get the JWT Token from the routes mentioned above
    b. Put that token in the Bearer Token in Authorization tab of postman request
    c. Hit the API, then it should work.

  • APIs:
    Merchant Account - Retrieve
    Merchant Account - Update
    Payment Connector - Create
    Payment Connector - Retrieve
    Payment Connector - List
    Payment Connector - Update
    Payment Connector - Delete
    Business Profile - Create
    Business Profile - Retrieve
    Business Profile - Update
    Business Profile - List
    Api Key - Create
    Api Key - Retrieve
    Api Key - Revoke
    Api Key - List
    Payments - Create
    Payments - Retrieve
    Payments - List
    Refunds - Create
    Refunds - Retrieve
    Refunds - List

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible
  • I added a CHANGELOG entry if applicable

@ThisIsMani ThisIsMani requested review from a team as code owners November 10, 2023 11:30
@ThisIsMani ThisIsMani self-assigned this Nov 10, 2023
@ThisIsMani ThisIsMani added A-framework Area: Framework C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Nov 10, 2023
@ThisIsMani ThisIsMani requested a review from a team as a code owner November 10, 2023 12:02
lsampras
lsampras previously approved these changes Nov 10, 2023
Copy link
Member

@lsampras lsampras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@apoorvdixit88 apoorvdixit88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
(We can discuss whether we want to keep the blocked_email list or we can totally remove it from signup flow)

@@ -1,3 +1,6 @@
#[cfg(feature = "olap")]
pub mod user;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is going to be small enough (only a few lines), you might as well have the module defined inline instead of keeping it in a separate file.

pub mod user {
    #[cfg(feature = "olap")]
    pub const MAX_NAME_LENGTH: usize = 70;
    #[cfg(feature = "olap")]
    pub const MAX_COMPANY_NAME_LENGTH: usize = 70;

    // USER ROLES
    #[cfg(any(feature = "olap", feature = "oltp"))]
    pub const ROLE_ID_ORGANIZATION_ADMIN: &str = "org_admin";
}

Not a necessary change however.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we add new APIs and new roles, this file is going to become big.

crates/router/src/utils/user/password.rs Show resolved Hide resolved
@likhinbopanna likhinbopanna removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Nov 13, 2023
@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 13, 2023
Merged via the queue into main with commit f88eee7 Nov 13, 2023
14 of 16 checks passed
@likhinbopanna likhinbopanna deleted the signup branch November 13, 2023 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-framework Area: Framework C-feature Category: Feature request or enhancement
Projects
No open projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

5 participants